package com.gcb.common.enums;

import java.util.Arrays;
import java.util.Optional;

/**
 * 船舶类型
 */
public enum ShipTypeEnum {
    PTHC(1, "普通货船"),
    JZXC(2, "集装箱船"),
    GZC(3, "滚装船"),
    ZBHC(4, "载驳货船"),
    SHC(5, "散货船"),
    JYC(6, "兼用船"),
    ZXC(7, "自卸船"),
    DYTC(8, "多用途船"),
    GHC(9, "干货船"),
    PBC(10, "平板船"),
    WNC(11, "挖泥船"),
    NBC(12, "泥驳船"),
    QZC(13, "起重船"),
    DZC(14, "打桩船"),
    HNTJBC(15, "混泥土搅拌船"),
    LJC(16, "垃圾船"),
    JBHC(17, "甲板货船"),
    ZXSC(18, "自卸砂船"),
    XNC(19, "吸泥船"),
    CSC(20, "采砂船"),
    OTHER(99, "其他");

    private final Integer code;
    private final String info;

    ShipTypeEnum(Integer code, String info) {
        this.code = code;
        this.info = info;
    }

    public Integer getCode() {
        return code;
    }

    public String getInfo() {
        return info;
    }

    public static String getInfoByCode(Integer code) {

        for (ShipTypeEnum shipType : ShipTypeEnum.values()) {
            if (shipType.getCode().equals(code)) {
                return shipType.getInfo();
            }
        }
        return null;
    }

    public static String getInfo(String type) {
        Integer i = Optional.ofNullable(type)
                .map(Integer::parseInt)
                .orElse(-1);
        return Optional.ofNullable(of(i))
                .map(ShipTypeEnum::getInfo)
                .orElse("");
    }

    public static String getInfo(Integer type) {
        return Optional.ofNullable(of(type))
                .map(ShipTypeEnum::getInfo)
                .orElse("");
    }

    public static ShipTypeEnum of(Integer code) {
        Optional<ShipTypeEnum> first = Arrays.stream(ShipTypeEnum.values()).filter(v -> v.getCode().equals(code)).findFirst();
        return first.orElse(null);
    }
}
